//
//  AboutUsViewController.m
//  WDFans
//
//  Created by Zhihong Yuan on 2/1/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "AboutUsViewController.h"
#import "UIAlertView+Utilities.h"
#import "ZHDataService.h"
#import "ActivityViewManager.h"
#import "ForwardWeiboViewController.h"

@implementation AboutUsViewController

@synthesize emailController;

#pragma mark - my own methods

- (IBAction)infoButtonClicked
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:kUrlOfAboutUsPage]];
}

- (IBAction)sendToSinaWeibo
{
    ForwardWeiboViewController *forwardController = [[ForwardWeiboViewController alloc] init];
    forwardController.weiboText = @"我正在试用西部数据粉丝俱乐部iphone版应用.";
    UINavigationController *naviController = [[UINavigationController alloc] initWithRootViewController:forwardController];
    [self.tabBarController presentModalViewController:naviController animated:YES];
    [naviController release];
    [forwardController release];
}

- (IBAction)sendEmailButtonClicked:(UIButton *)btn
{
    if(![ShowComposeViewControlller canSendEmail])
    {
        [UIAlertView showAlertViewWithTitle:@"Your device is not configured for sending mail" message:@"Reset your config" andDelegate:nil];
        return;
    }
    ShowComposeViewControlller *compose = [[ShowComposeViewControlller alloc] init];
    self.emailController = compose;
    [compose release];
    self.emailController.subject = @"我正在试用西部数据俱乐部！";
    self.emailController.content = @"赶紧来用西部数据俱乐部哦，非常好用，亲！";
    self.emailController.delegate = self;
    NSArray *receiver = [NSArray arrayWithObject:kEmailOfTheCompany];
    self.emailController.recipients = receiver;
    [self.emailController displayMailViewForController:self];
}

#pragma mark - View lifecycle
- (void)dealloc
{
    [emailController release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"关于";
    [self setBackgroundImageViewForTabView];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

#pragma -
#pragma ShowComposeViewControlller delegate methods
- (void)composeController:(ShowComposeViewControlller *)controller didFinishWithResultForMessage:(MessageComposeResult)result
{
    return;
}

- (void)composeController:(ShowComposeViewControlller *)controller didFinishWithResultForMail:(MFMailComposeResult)result error:(NSError *)error
{
    switch (result)
	{
		case MFMailComposeResultCancelled:
			NSLog(@"Result: canceled");
			break;
		case MFMailComposeResultSaved:
			NSLog(@"Result: saved");
			break;
		case MFMailComposeResultSent:
			NSLog(@"Result: sent");
			break;
		case MFMailComposeResultFailed:
			NSLog(@"Result: failed");
			break;
		default:
			NSLog(@"Result: not sent");
			break;
	}
	[self dismissModalViewControllerAnimated:YES];
}
@end
